<?php
/**
 * Created by PhpStorm.
 * User: liujialiang
 * Date: 2017/9/22
 * Time: 14:12
 */

namespace App\Model;


use lib\Model;
use App\Model\UserModel;

class FriendsModel extends Model
{
    protected $table='friends';

   public function friends(){
   	 $Data=[];
     $fids=[];
        $f=new Self;
        $frData=$f->get(['uid'=>$_SESSION['user_id']]);
        foreach($frData as $v){
            $fids[]=$v['fid'];
        }
        $get_user=new UserModel();
        $userData=$get_user->get();
        $Data[] =$userData;
        //去掉登录用户的信息
        foreach($userData as $k=>$v){
            if($v['id']==$_SESSION['user_id']){
                unset($userData[$k]);
            }
            //去掉好友信息
            if(in_array($v['id'],$fids)){
                unset($userData[$k]);
            }
        }
        //返回好友信息
	        $fData=$get_user->join(['friends'=>'fid'],['friends.uid'=>$_SESSION['user_id']]);
	       $Data[] = $fData;
	        return $Data;
    		}
    }